package com.fengmi.service.impl;

import com.fengmi.entity.StatOrder;
import com.fengmi.mapper.OrderStatMapper;
import com.fengmi.service.OrderStatService;
import com.fengmi.vo.InfoResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Author: 施俊豪
 * Date: 2022/2/8 14:43
 * Note:
 */
@Transactional
@Service
public class OrderStatServiceImpl implements OrderStatService {

    @Autowired(required = false)
    private OrderStatMapper orderStatMapper;

    /**
     * @Note : 每日凌晨1点,统计前一天的订单情况
     * @Date : 2022-02-08 14:44:09
     * @Author : 清酒吖
    */
    @Override
    public InfoResult statOrderByDay() {

        // 统计前一天的订单情况
        StatOrder orderByDay = orderStatMapper.findOrderByDay();

        // 保存到定时订单表中
        Integer row = orderStatMapper.insertStatOrderByDay(orderByDay);

        return new InfoResult(true,"success","");
    }

    /**
     * @Note : 根据时间查询定时订单统计
     * @Date : 2022-02-08 17:42:45
     * @Author : 清酒吖
    */
    @Override
    public InfoResult<List<StatOrder>>  statOrderByTime(String start, String end) {
        List<StatOrder> orderByTime = orderStatMapper.findOrderByTime(start, end);
        return new InfoResult<List<StatOrder>> (true,"success",orderByTime);
    }
}
